Ext.onReady(function() {
    // 使用表单提示
    Ext.QuickTips.init();
    Ext.form.Field.prototype.msgTarget = 'side';

    var loginForm = new Ext.FormPanel({
        baseCls:'x-plain',
        labelAlign:'right',
        frame:false,
        bodyStyle:'padding:35px 5px 5px 5px;',
        defaults:{allowBlank:false,xtype:'textfield',cls:'inputSty'},

        items: [{
            name:'username',
            jwcid:'username',
            fieldLabel: '帐号',
            blankText:'帐号必需填写'
        },{
            name:'password',
            jwcid:'password',
            fieldLabel: '密码',
            inputType:'password',
            blankText:'密码必需填写'
        }],

        buttons: [{
            text: '登录',
            type:'submit',
            handler:function() {
                if(loginForm.form.isValid()) {
                    Ext.MessageBox.show({
                        title:'请稍等',
                        msg:'正在加载...',
                        progressText:'',
                        width:300,
                        progress:true,
                        closable:false,
                        animEl:'loading'
                    });

                    //控制进度速度
                    var f = function(v) {
                        return function() {
                            var i = v/11;
                            Ext.MessageBox.updateProgress(i, '');
                        };
                    };
                    for(var i = 1; i < 13; i++) {
                        setTimeout(f(i), i * 150);
                    }

                    // 提交到服务器
                    var m = loginForm.form.doAction('submit', {
                        url:'login.act',
                        method:'post',
                        params:'',
                        success:function(form,action) {
                            if (action.result.msg == 'ok') {
                                document.location = 'main.html';
                            } else {
                                Ext.Msg.alert('登录错误', action.result.msg);
                            }
                        },
                        failure:function() {
                            Ext.Msg.alert('错误', '服务器出现错误清稍后再试！');
                        }
                    });
                }
            }
        },{
            text: '重置',
            handler : function() {
                loginForm.form.reset();
            }
        }]

    });

    var win = new Ext.Window({
        title:'用户登录',
        layout:'fit',
        width:490,
        height:270,
        applyTo:'loginWin',
        resizable:false,
        draggable:false,
        closable:false,
        plain:true,
        buttonAlign:'center',
        items:loginForm
    })

    win.add(loginForm);
    win.show();

});

